
// 模拟商品详情数据
const goodsDetails = {
  1: {
    id: 1,
    name: 'Quantum Chronograph Watch - Limited Edition',
    price: '1299.00',
    originalPrice: '1599.00',
    description: '这款Quantum Chronograph手表采用精密机械机芯，搭配蓝宝石玻璃表镜和316L不锈钢表壳，防水深度达100米。表盘采用瑞士Super-LumiNova夜光技术，确保在黑暗环境中也能清晰读时。表带使用意大利进口小牛皮，佩戴舒适。这是一款集功能性与美学设计于一体的精品腕表，适合各种正式场合佩戴。',
    images: [
      'https://images.unsplash.com/photo-1523275335684-37898b6baf30?q=80&w=1000&auto=format&fit=crop',
      'https://images.unsplash.com/photo-1522312346375-d1a52e2b99b3?q=80&w=1000&auto=format&fit=crop',
      'https://images.unsplash.com/photo-1508057198894-247b23fe5ade?q=80&w=1000&auto=format&fit=crop'
    ],
    descriptionImages: [
      'https://images.unsplash.com/photo-1434056886845-dac89ffe9b56?q=80&w=1000&auto=format&fit=crop',
      'https://images.unsplash.com/photo-1547996160-81dfa63595aa?q=80&w=1000&auto=format&fit=crop'
    ],
    specs: {
      colors: [
        { name: '银色', value: 'silver' },
        { name: '金色', value: 'gold' },
        { name: '黑色', value: 'black' }
      ],
      sizes: [
        { name: '40mm', value: '40mm', available: true },
        { name: '42mm', value: '42mm', available: true },
        { name: '44mm', value: '44mm', available: false }
      ]
    },
    shipping: {
      location: '北京',
      method: '顺丰速运',
      fee: '免运费',
      estimatedDelivery: '明天送达'
    },
    stock: 86,
    likes: 2458,
    sales: 1289,
    comments: 356,
    rating: 4.8,
    reviewCount: 245
  },
  2: {
    id: 2,
    name: 'Digital Smart Watch',
    price: '899.00',
    originalPrice: '1099.00',
    description: '这款数字智能手表配备高清触摸屏和多种健康监测功能，包括心率监测、血氧监测和睡眠追踪。支持多种运动模式，防水深度达50米，续航时间长达7天。兼容iOS和Android系统，支持蓝牙通话和消息提醒。',
    images: [
      'https://images.unsplash.com/photo-1546868871-7041f2a55e12?q=80&w=1000&auto=format&fit=crop',
      'https://images.unsplash.com/photo-1579586337278-3befd40fd17a?q=80&w=1000&auto=format&fit=crop'
    ],
    descriptionImages: [
      'https://images.unsplash.com/photo-1434056886845-dac89ffe9b56?q=80&w=1000&auto=format&fit=crop'
    ],
    specs: {
      colors: [
        { name: '黑色', value: 'black' },
        { name: '白色', value: 'white' }
      ],
      sizes: [
        { name: '标准', value: 'standard', available: true }
      ]
    },
    shipping: {
      location: '上海',
      method: '京东快递',
      fee: '免运费',
      estimatedDelivery: '2-3天送达'
    },
    stock: 120,
    likes: 1856,
    sales: 968,
    comments: 245,
    rating: 4.6,
    reviewCount: 180
  },
  3: {
    id: 3,
    name: 'Classic Analog Watch',
    price: '599.00',
    originalPrice: '799.00',
    description: '这款经典模拟手表采用瑞士机芯，精工细作，表壳为316L不锈钢材质，表镜为蓝宝石玻璃，防刮耐磨。表带为真皮材质，佩戴舒适。简约大方的设计适合各种场合佩戴。',
    images: [
      'https://images.unsplash.com/photo-1524805444758-089113d48a6d?q=80&w=1000&auto=format&fit=crop',
      'https://images.unsplash.com/photo-1533139502658-0198f920d8e8?q=80&w=1000&auto=format&fit=crop'
    ],
    descriptionImages: [
      'https://images.unsplash.com/photo-1434056886845-dac89ffe9b56?q=80&w=1000&auto=format&fit=crop'
    ],
    specs: {
      colors: [
        { name: '棕色', value: 'brown' },
        { name: '黑色', value: 'black' }
      ],
      sizes: [
        { name: '38mm', value: '38mm', available: true },
        { name: '40mm', value: '40mm', available: true }
      ]
    },
    shipping: {
      location: '广州',
      method: '中通快递',
      fee: '免运费',
      estimatedDelivery: '3-5天送达'
    },
    stock: 95,
    likes: 1245,
    sales: 756,
    comments: 189,
    rating: 4.7,
    reviewCount: 150
  },
  4: {
    id: 4,
    name: 'Sport Fitness Watch',
    price: '499.00',
    originalPrice: '699.00',
    description: '这款运动健身手表专为运动爱好者设计，具有GPS定位、心率监测、计步器等功能。防水深度达100米，适合游泳和潜水。表带采用硅胶材质，轻便舒适，适合长时间佩戴。',
    images: [
      'https://images.unsplash.com/photo-1508685096489-7aacd43bd3b1?q=80&w=1000&auto=format&fit=crop',
      'https://images.unsplash.com/photo-1434494878577-86c23bcb06b9?q=80&w=1000&auto=format&fit=crop'
    ],
    descriptionImages: [
      'https://images.unsplash.com/photo-1434056886845-dac89ffe9b56?q=80&w=1000&auto=format&fit=crop'
    ],
    specs: {
      colors: [
        { name: '黑色', value: 'black' },
        { name: '蓝色', value: 'blue' },
        { name: '红色', value: 'red' }
      ],
      sizes: [
        { name: '标准', value: 'standard', available: true }
      ]
    },
    shipping: {
      location: '深圳',
      method: '顺丰速运',
      fee: '免运费',
      estimatedDelivery: '1-2天送达'
    },
    stock: 150,
    likes: 2056,
    sales: 1120,
    comments: 278,
    rating: 4.9,
    reviewCount: 220
  }
}

// 模拟商品评论数据
const goodsComments = {
  1: [
    {
      id: 101,
      username: '王小明',
      avatar: 'https://randomuser.me/api/portraits/men/32.jpg',
      rating: 5,
      content: '手表质量非常好，做工精细，走时准确。包装也很精美，很适合送礼。客服态度也很好，有问题都及时解答。',
      images: ['https://images.unsplash.com/photo-1539874754764-5a96559165b0?q=80&w=300&auto=format&fit=crop'],
      date: '2023-12-15'
    },
    {
      id: 102,
      username: '李小红',
      avatar: 'https://randomuser.me/api/portraits/women/44.jpg',
      rating: 4,
      content: '整体来说不错，但是表带有点硬，需要一段时间适应。表盘设计很漂亮，夜光效果也很好。',
      images: [],
      date: '2023-11-28'
    },
    {
      id: 103,
      username: '张三',
      avatar: 'https://randomuser.me/api/portraits/men/22.jpg',
      rating: 5,
      content: '非常满意的一次购物体验，手表质量超出预期，走时精准，外观设计时尚大气。',
      images: ['https://images.unsplash.com/photo-1434056886845-dac89ffe9b56?q=80&w=300&auto=format&fit=crop'],
      date: '2023-11-15'
    },
    {
      id: 104,
      username: '赵四',
      avatar: 'https://randomuser.me/api/portraits/men/36.jpg',
      rating: 4,
      content: '手表很漂亮，但是价格有点贵。总体来说还是值得购买的，毕竟是限量版。',
      images: [],
      date: '2023-10-28'
    }
  ],
  2: [
    {
      id: 201,
      username: '陈小明',
      avatar: 'https://randomuser.me/api/portraits/men/42.jpg',
      rating: 5,
      content: '这款智能手表功能非常强大，续航也很好，用了一周才充电一次。',
      images: ['https://images.unsplash.com/photo-1579586337278-3befd40fd17a?q=80&w=300&auto=format&fit=crop'],
      date: '2023-12-10'
    },
    {
      id: 202,
      username: '王丽',
      avatar: 'https://randomuser.me/api/portraits/women/24.jpg',
      rating: 4,
      content: '手表很好用，但是有时候会出现卡顿的情况，希望后续软件更新能解决这个问题。',
      images: [],
      date: '2023-11-20'
    }
  ],
  3: [
    {
      id: 301,
      username: '李明',
      avatar: 'https://randomuser.me/api/portraits/men/52.jpg',
      rating: 5,
      content: '这款经典手表非常适合正式场合佩戴，做工精细，走时准确。',
      images: [],
      date: '2023-12-05'
    }
  ],
  4: [
    {
      id: 401,
      username: '张伟',
      avatar: 'https://randomuser.me/api/portraits/men/62.jpg',
      rating: 5,
      content: '这款运动手表防水效果很好，游泳时佩戴完全没问题，心率监测也很准确。',
      images: ['https://images.unsplash.com/photo-1434494878577-86c23bcb06b9?q=80&w=300&auto=format&fit=crop'],
      date: '2023-12-01'
    }
  ]
}

// 模拟商品列表数据
const goodsList = [
  {
    id: 1,
    goodsNo: 'G2023001',
    productName: '量子计时手表',
    cateName: '智能手表',
    detail: '这是一款高科技量子计时手表，采用最新的量子技术，精准计时，永不停止。',
    images: 'https://images.unsplash.com/photo-1523275335684-37898b6baf30?q=80&w=1000&auto=format&fit=crop',
    isOnSale: '1',
    hot: '1',
    payIcon: 'USDT,ETH,BTC',
    prodSort: 1,
    remark: '限量发售',
    createdAt: '2023-01-01 12:00:00',
    updatedAt: '2023-01-01 12:00:00',
    specs: [
      {
        id: 1,
        goodsId: 1,
        specName: '标准版',
        usdtPrice: '1299.00',
        stock: 100,
        sales: 50,
        createdAt: '2023-01-01 12:00:00',
        updatedAt: '2023-01-01 12:00:00'
      },
      {
        id: 2,
        goodsId: 1,
        specName: '豪华版',
        usdtPrice: '1999.00',
        stock: 50,
        sales: 20,
        createdAt: '2023-01-01 12:00:00',
        updatedAt: '2023-01-01 12:00:00'
      }
    ]
  },
  {
    id: 2,
    goodsNo: 'G2023002',
    productName: '数字智能手表',
    cateName: '智能手表',
    detail: '这是一款功能强大的数字智能手表，支持多种运动模式和健康监测。',
    images: 'https://images.unsplash.com/photo-1546868871-7041f2a55e12?q=80&w=1000&auto=format&fit=crop',
    isOnSale: '1',
    hot: '1',
    payIcon: 'USDT,ETH',
    prodSort: 2,
    remark: '热销产品',
    createdAt: '2023-01-02 12:00:00',
    updatedAt: '2023-01-02 12:00:00',
    specs: [
      {
        id: 3,
        goodsId: 2,
        specName: '标准版',
        usdtPrice: '899.00',
        stock: 80,
        sales: 30,
        createdAt: '2023-01-02 12:00:00',
        updatedAt: '2023-01-02 12:00:00'
      }
    ]
  },
  {
    id: 3,
    goodsNo: 'G2023003',
    productName: '经典模拟手表',
    cateName: '传统手表',
    detail: '这是一款经典设计的模拟手表，采用瑞士机芯，精工细作。',
    images: 'https://images.unsplash.com/photo-1524805444758-089113d48a6d?q=80&w=1000&auto=format&fit=crop',
    isOnSale: '1',
    hot: '1',
    payIcon: 'USDT,BTC',
    prodSort: 3,
    remark: '经典款式',
    createdAt: '2023-01-03 12:00:00',
    updatedAt: '2023-01-03 12:00:00',
    specs: [
      {
        id: 4,
        goodsId: 3,
        specName: '标准版',
        usdtPrice: '599.00',
        stock: 120,
        sales: 45,
        createdAt: '2023-01-03 12:00:00',
        updatedAt: '2023-01-03 12:00:00'
      }
    ]
  },
  {
    id: 4,
    goodsNo: 'G2023004',
    productName: '运动健身手表',
    cateName: '智能手表',
    detail: '这是一款专为运动爱好者设计的健身手表，防水防震，续航持久。',
    images: 'https://images.unsplash.com/photo-1508685096489-7aacd43bd3b1?q=80&w=1000&auto=format&fit=crop',
    isOnSale: '1',
    hot: '1',
    payIcon: 'USDT',
    prodSort: 4,
    remark: '运动必备',
    createdAt: '2023-01-04 12:00:00',
    updatedAt: '2023-01-04 12:00:00',
    specs: [
      {
        id: 5,
        goodsId: 4,
        specName: '标准版',
        usdtPrice: '499.00',
        stock: 150,
        sales: 70,
        createdAt: '2023-01-04 12:00:00',
        updatedAt: '2023-01-04 12:00:00'
      }
    ]
  },
  {
    id: 5,
    goodsNo: 'G2023005',
    productName: '限量版手表',
    cateName: '奢侈手表',
    detail: '这是一款限量发售的奢侈手表，采用18K金材质，镶嵌钻石，尽显尊贵。',
    images: 'https://images.unsplash.com/photo-1434056886845-dac89ffe9b56?q=80&w=1000&auto=format&fit=crop',
    isOnSale: '1',
    hot: '1',
    payIcon: 'USDT,ETH,BTC',
    prodSort: 5,
    remark: '奢华体验',
    createdAt: '2023-01-05 12:00:00',
    updatedAt: '2023-01-05 12:00:00',
    specs: [
      {
        id: 6,
        goodsId: 5,
        specName: '限量版',
        usdtPrice: '1599.00',
        stock: 30,
        sales: 15,
        createdAt: '2023-01-05 12:00:00',
        updatedAt: '2023-01-05 12:00:00'
      }
    ]
  },
  {
    id: 6,
    goodsNo: 'G2023006',
    productName: '儿童智能手表',
    cateName: '儿童手表',
    detail: '这是一款专为儿童设计的智能手表，具有定位、通话、SOS等功能。',
    images: 'https://images.unsplash.com/photo-1542496658-e33a6d0d50f6?q=80&w=1000&auto=format&fit=crop',
    isOnSale: '1',
    hot: '0',
    payIcon: 'USDT',
    prodSort: 6,
    remark: '儿童安全',
    createdAt: '2023-01-06 12:00:00',
    updatedAt: '2023-01-06 12:00:00',
    specs: [
      {
        id: 7,
        goodsId: 6,
        specName: '标准版',
        usdtPrice: '299.00',
        stock: 200,
        sales: 85,
        createdAt: '2023-01-06 12:00:00',
        updatedAt: '2023-01-06 12:00:00'
      }
    ]
  }
]

/**
 * 获取商品列表
 * @param {Object} params 查询参数
 * @returns {Object} 商品列表数据
 */
export function getGoodsList(params) {
  const { page = 1, size = 10, productName = '', cateName = '', hot = '' } = params
  
  // 根据查询条件过滤
  let filteredList = [...goodsList]
  if (productName) {
    filteredList = filteredList.filter(item => item.productName.includes(productName))
  }
  if (cateName) {
    filteredList = filteredList.filter(item => item.cateName === cateName)
  }
  if (hot) {
    filteredList = filteredList.filter(item => item.hot === hot)
  }
  
  // 排序
  if (params.prodSort > 0) {
    filteredList.sort((a, b) => a.prodSort - b.prodSort)
  } else {
    filteredList.sort((a, b) => b.prodSort - a.prodSort)
  }
  
  const total = filteredList.length
  const list = filteredList.slice((page - 1) * size, page * size)
  
  return {
    code: 0,
    message: '获取商品列表成功',
    data: {
      list: list,
      count: total
    },
    total: total,
    page: parseInt(page),
    size: parseInt(size)
  }
}

/**
 * 获取商品详情
 * @param {string|number} id 商品ID
 * @returns {Object} 商品详情数据
 */
export function getGoodsDetail(id) {
  const goodsId = parseInt(id)
  const detail = goodsDetails[goodsId]
  
  if (!detail) {
    return {
      code: 404,
      message: '商品不存在',
      data: null
    }
  }
  
  return {
    code: 0,
    message: '获取商品详情成功',
    data: detail
  }
}

/**
 * 获取商品评论
 * @param {string|number} id 商品ID
 * @param {Object} params 查询参数
 * @returns {Object} 商品评论数据
 */
export function getGoodsComments(id, params) {
  const goodsId = parseInt(id)
  const { page = 1, size = 10 } = params
  
  const comments = goodsComments[goodsId] || []
  const total = comments.length
  const list = comments.slice((page - 1) * size, page * size)
  
  return {
    code: 0,
    message: '获取商品评论成功',
    data: list,
    total: total,
    page: parseInt(page),
    size: parseInt(size)
  }
}

/**
 * 获取商品所有评论
 * @param {string|number} id 商品ID
 * @returns {Object} 商品所有评论数据
 */
export function getAllGoodsComments(id) {
  const goodsId = parseInt(id)
  const comments = goodsComments[goodsId] || []
  
  return {
    code: 0,
    message: '获取商品所有评论成功',
    data: comments
  }
}

/**
 * 获取推荐商品
 * @param {string|number} id 商品ID
 * @param {number} limit 限制数量
 * @returns {Object} 推荐商品数据
 */
export function getRecommendedGoods(id, limit = 4) {
  const goodsId = parseInt(id)
  
  // 从商品详情中获取推荐商品，排除当前商品
  const recommendedList = Object.values(goodsDetails)
    .filter(item => item.id !== goodsId)
    .slice(0, limit)
    .map(item => ({
      id: item.id,
      name: item.name,
      price: item.price,
      image: item.images[0]
    }))
  
  return {
    code: 0,
    message: '获取推荐商品成功',
    data: recommendedList
  }
}
